



$(document).ready(function(){
	var currentButton=null;
	var obj=$(".monthList")
	var showNum=3;
	var speed=500;
	var isTween=false;
	var space=obj.find("li").width();
		obj.css("position","absolute")
		obj.css("left","0")
		obj.css("top","0")

	var childArray=new Array();
	var nowArray=new Array();
	var k=0;
	var s=0;
		$(".monthList li").each(function(i){
			var cobj=$(this);
			cobj.css("position","absolute")
			cobj.css("left",i*space)
				
			if(i>=showNum)
			{
				childArray[k]=$(this)
					k++;
			}
			if(i<showNum)
			{
				nowArray[s]=$(this)
					s++;
			}
		})
	
	function toLeft(){
		isTween=true;
		var newobj=childArray[0]
			newobj.css("left",showNum*space)
			
		for(var i=0;i<nowArray.length;i++)
		{
			nowArray[i].animate({
				left:"-="+space
			},speed)
		}
		newobj.animate({
			left:"-="+space
		},speed,function(){
			
			isTween=false;
			var st=nowArray.shift();
			childArray.push(st)
			childArray.shift();
			nowArray.push(newobj)
		})

	
	}
	
	function toRight(){
		isTween=true;
		var newobj=childArray.pop();
			newobj.css("left",-space)
			nowArray.unshift(newobj)
			
		for(var i=0;i<nowArray.length;i++)
		{
			nowArray[i].animate({
				left:"+="+space
			},speed,function(){
				
				isTween=false; 	
			})
		}
		var st=nowArray.pop()
		childArray.unshift(st)
	}




	$("#cleft").click(function(){
		if(!isTween)
		{
			toLeft()
		}
	})

	$("#cright").click(function(){

		if(!isTween)
		{
			toRight();
		}
	})

	obj.find("li").click(function(){/*选择不同月份*/
		if(currentButton!=null)
		{
			var oriClass=currentButton.attr("oclass");
			currentButton.removeClass("focus")
		}
	
		$(this).addClass("focus")
		currentButton=$(this)
	})

	$("#seeBack").click(function(){/*返回本月抽奖按钮*/
		var date=new Date();
		obj.find("li").eq(date.getMonth()).trigger("click")
	})


	setpos()//设置浮动窗口位置

})

$(window).resize(function(){
	setpos()
})

function setpos(){
	var x=$("#cleft").position().left+$("#cleft").width();
	var y=$("#cleft").position().top;
	$(".monthList").css("left",x+"px")
	$(".monthList").css("top",y+"px")
}